// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Eggman Laser Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer
private alias object.value1 : object.lastGroundPos.x

// Path ID Aliases
private alias 0 : PATH_A


// ========================
// Events
// ========================

event ObjectUpdate
	object.xpos += object.xvel

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -16, -2, 16, 2, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			CallFunction(Player_Hit)
		end if
	next

	temp0 = object.xpos
	temp0 >>= 20
	if temp0 != object.lastGroundPos.x
		object.lastGroundPos.x = object.xpos
		object.lastGroundPos.x >>= 20
		ObjectTileGrip(CSIDE_FLOOR, 0, 1, PATH_A)
		if checkResult == true
			temp0 = object.lastGroundPos.x
			temp0 <<= 20
			temp0 += 0x80000
			temp1 = object.ypos
			temp1 += 0x20000
			CreateTempObject(TypeName[Eggman Flame], 0, temp0, temp1)

			PlaySfx(SfxName[Laser Skim], false)
		end if
	end if

	if object.timer < 2
		object.timer++
	else
		object.frame = 1
	end if

	if object.outOfBounds == true
		object.type = TypeName[Blank Object]
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone07")
	if checkResult == true
		LoadSpriteSheet("OOZ/Objects.gif")
		SpriteFrame(-16, -2, 16, 4, 149, 241)
		SpriteFrame(-16, -2, 32, 4, 149, 241)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -2, 16, 4, 594, 176)
		SpriteFrame(-16, -2, 32, 4, 594, 176)
	end if
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone07")
	if checkResult == true
		LoadSpriteSheet("OOZ/Objects.gif")
		SpriteFrame(-16, -2, 16, 4, 149, 241)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -2, 16, 4, 594, 176)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
